<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>用户管理</title>
    <link rel="stylesheet" type="text/css" href="../css/default.css">
    <link rel="stylesheet" type="text/css" href="../js/jquery-easyui-1.4.2/themes/gray/easyui.css">
    <link rel="stylesheet" type="text/css" href="../js/jquery-easyui-1.4.2/themes/icon.css"/>
    <script type="text/javascript" src="../js/data.js"></script>
    <script type="text/javascript" src="../js/jquery-easyui-1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="../js/jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../js/extends.js"></script>
    <script type="text/javascript" src="../js/common.js"></script>
    <script type="text/javascript" src="../js/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>
    <style>
		.icon-margin{
			margin-left:8px;
		}
		.datagrid-btable tr{
			height: 30px;
		}
	</style>
	
    <script type="text/javascript">
    	var pageNumber = 1, pageSize = 20, pageNum = 1;
    
        $(function () {
        	$("<div id='bg_id' class=\"datagrid-mask\"></div>").css({display:"block",width:"100%",height:$(window).height()}).appendTo("body");
        	$("<div id='load_id' class=\"datagrid-mask-msg\"></div>").html("正在处理，请稍候。。。").appendTo("body").css({display:"block",left:($(document.body).outerWidth(true) - 190) / 2,top:($(window).height() - 45) / 2}); 
            $("#tt").datagrid({
                height: $("#body").height() - $('#search_area').height() - 5,
                width: $("#body").width(),
                idField: 'id',
                singleSelect: true,
                nowrap: true,
                fitColumns: true,
                rownumbers: false,
                showPageList: true,
                columns: [[
                    {field: 'rowNum', title: '序号', width: 20, halign: "center", align: "left"},
                    {field: 'rsvID', title: '规则ID', width: 100, halign: "center", align: "left"},
                    {field: 'rsvName', title: '规则名称', width: 40, halign: "center", align: "left"},
                    {field: 'rsvDescrible', title: '规则简介', width: 100, halign: "center", align: "left"},
                    {field: 'baseCount', title: '初始数量', width: 30, halign: "center", align: "left"},
                    {field: 'baseMultiple', title: '基础倍数', width: 30, halign: "center", align: "left"},
                    {field: 'backupStatus', title: '归档状态', width: 50, halign: "center", align: "left"},
                    {field: 'createDate', title: '创建日期', width: 100, halign: "center", align: "left"},
                    {field: 'lastUpdateDate', title: '最后变更日期', width: 100, halign: "center", align: "left"},
                    {
                        field: 'department', title: '操作', width: 100, halign: "center", align: "left",
                        formatter: function (value, row, index) {
                        	var bt_data = "";
                        	if(row.backupStatus =='未归档'){
	                        	bt_data = '<a title="详情" href="javascript:void(0);" onclick="rsvDetail(\'' + row.rsvID + '\')" class="gridButton easyui-tooltip" iconCls="icon-search"></a><a title="导出" href="javascript:void(0);" onclick="exportData(\'' + row.rsvID + '\',0,\''+row.rsvName+'\',\''+row.rsvDescrible+'\')" class="gridButton icon-margin easyui-tooltip" iconCls="icon-redo"></a><a title="删除" href="javascript:void(0);" onclick="deleteRsv(\'' + row.rsvID + '\')" class="gridButton icon-margin easyui-tooltip" iconCls="icon-remove"></a><a title="修改" href="javascript:void(0);" id="edit" onclick="modifyRsv(\'' + row.rsvID + '\',\'' + row.rowNum + '\')" class="gridButton icon-margin easyui-tooltip" iconCls="icon-edit" ></a><a title="归档" href="javascript:void(0);" onclick="backupRsv(\'' + row.rsvID + '\',\'' + row.rowNum + '\')" class="gridButton icon-margin easyui-tooltip" iconCls="icon-back"></a>';
                        	}else{
                        		bt_data = '<a title="详情" href="javascript:void(0);" onclick="rsvDetail(\'' + row.rsvID + '\')" class="gridButton easyui-tooltip" iconCls="icon-search"></a><a title="导出" href="javascript:void(0);" onclick="exportData(\'' + row.rsvID + '\',1,\''+row.rsvName+'\',\''+row.rsvDescrible+'\')" class="gridButton icon-margin easyui-tooltip" iconCls="icon-redo"></a>';
                        	}
                            return bt_data;
                        }
                    }
                ]],
                toolbar: '#tt_btn',
                pagination: true,
                onLoadSuccess: function (data) {
                   $("a.gridButton").linkbutton();
                   $("#load_id").hide();
                   $("#bg_id").hide();
                },
                onBeforeLoad:function(){
                  $("#load_id").show();
                  $("#bg_id").show();
                }
            });

          //获取DataGrid分页组件对象
            var p = $("#tt").datagrid('getPager');
            //设置分页组件参数
            var obj = $(p).pagination('options');
            $(p).pagination({
                pageNumber: obj.pageNumber,
                pageSize: pageSize,
            	showPageList:true,
                onSelectPage: function (pageNumber, pageSize) {
                    getData(pageNumber, pageSize);
                }
            });
            getData(pageNumber, pageSize);
 
          //查询数据
            function getData(pageNumber, pageSize) {
            	var userName = $("#userName").val();
                var begindate = $("#begindate").datebox('getValue'); 
                var enddate = $("#enddate").datebox('getValue');
                var backupStatus = $("#backup_status").val();
                
                if (backupStatus == '全部') {
            		backupStatus = null;
            	}
            	else if (backupStatus == '未归档') {
            		backupStatus = 0;
            	}
            	else if (backupStatus == '已归档') {
            		backupStatus = 1;
            	}
				var p = $("#tt").datagrid('getPager');
	            var obj = $(p).pagination('options');
	         	$("#tt").datagrid('loadData', getRsvList(obj.pageNumber, obj.pageSize, begindate, enddate, backupStatus, userName));
            }
          
            //新增弹出框
            $("#save").on("click", function () {
                $parent("#parent_win").window({
                    width: 714,
                    height: 610,
                    href: '/web-manager/rsv/addResvRule.html',
                    title: '新增预约规则',
                    onClose:function () {
                    	var userName = $("#userName").val();
		                var begindate = $("#begindate").datebox('getValue'); 
		                var enddate = $("#enddate").datebox('getValue');
		                var backupStatus = $("#backup_status").val();
		                
		                if (backupStatus == '全部') {
		            		backupStatus = null;
		            	}
		            	else if (backupStatus == '未归档') {
		            		backupStatus = 0;
		            	}
		            	else if (backupStatus == '已归档') {
		            		backupStatus = 1;
		            	}
						var p = $("#tt").datagrid('getPager');
			            var obj = $(p).pagination('options');
			         	$("#tt").datagrid('loadData', getRsvList(obj.pageNumber, obj.pageSize, begindate, enddate, backupStatus, userName));
			         	
                    }
                });
            });
            
            //同步
            $("#syncRsvs").on("click", function () {
            	$.post("/web-manager/rsvManager/syncRsvs.do", 
     				function(result){
            			if (result.code == 0 || result.code == "0") {
							$.messager.show({title: '提示', msg: "同步成功"});
	    				}
						else {
							var errorInfo = "同步失败," + result.errorDescription;;
	    					$.messager.show({title: '错误', msg: errorInfo});
						}
            			
     			 });
            });
            
            /*搜索*/
            $("#search").on("click", function () {
            	$.post("/web-promotion/rsvInterface/saveData.do",{v_rsvID : "0000000017B9759526006A42E053433210ACCF47"},
         				function(result){
                			if (result.code == 0 || result.code == "0") {
    							$.messager.show({title: '提示', msg: "同步成功"});
    	    				}
    						else {
    							var errorInfo = "同步失败," + data.errorDescription;;
    	    					$.messager.show({title: '错误', msg: errorInfo});
    						}
                			
         			 });
            	
                /* var userName = $("#userName").val();
                var begindate = $("#begindate").datebox('getValue'); 
                var enddate = $("#enddate").datebox('getValue');
                var backupStatus = $("#backup_status").val();
                
                if (backupStatus == '全部') {
            		backupStatus = null;
            	}
            	else if (backupStatus == '未归档') {
            		backupStatus = 0;
            	}
            	else if (backupStatus == '已归档') {
            		backupStatus = 1;
            	}
                var p = $("#tt").datagrid('getPager');
	            var obj = $(p).pagination('options');
	            obj.pageNumber="1";
            	$("#tt").datagrid('loadData', getRsvList(pageNum, obj.pageSize, begindate, enddate, backupStatus, userName)); */
            });
            
            /*重置*/
            $("#reset").on("click", function () {
                $('#ff').form('clear');
                $("#ff").form('reset');
                return;
            });
            $(".datebox :text").attr("readonly", "readonly");
            $('#dd').tooltip({
                position: 'top',
                content: '<span style="color:#f0f0f0">This is the tooltip message.</span>',
                onShow: function () {
                    $(this).tooltip('tip').css({backgroundColor: '#666', borderColor: '#666'});
                }
            });
            
            $("#backup_status").change(function(){
            	var idFalg = $("#backup_status option:selected").attr("id");
            });
            
        });
        
		//删除
        function deleteRsv(v_rsvID) {
    		$.messager.confirm('提示','真的要删除吗？',function(r){
    			if (r){
    				$.post("/web-manager/rsvManager/deleteRsv.do", 
   						{v_rsvID : v_rsvID},
   						function(result){
   							if (result.code != 0 && result.code != "0") {
   								var errorInfo = "删除失败," + result.errorDescription;
   		    					$.messager.show({title: '错误', msg: errorInfo});
   		    				}
   							else {
   								$.messager.show({title: '提示', msg: "删除成功"});
   								var userName = $("#userName").val();
   				                var begindate = $("#begindate").datebox('getValue'); 
   				                var enddate = $("#enddate").datebox('getValue');
   				                var backupStatus = $("#backup_status").val();
   				                
   				                if (backupStatus == '全部') {
   				            		backupStatus = null;
   				            	}
   				            	else if (backupStatus == '未归档') {
   				            		backupStatus = 0;
   				            	}
   				            	else if (backupStatus == '已归档') {
   				            		backupStatus = 1;
   				            	}
   								var p = $("#tt").datagrid('getPager');
   					            var obj = $(p).pagination('options');
   					            var pageNumber=obj.pageNumber;
   					            if((obj.pageNumber-1)*obj.pageSize>=(obj.total-1)){
   					            	pageNumber=pageNumber-1;
   					            }
   					         	$("#tt").datagrid('loadData', getRsvList(pageNumber, obj.pageSize, begindate, enddate, backupStatus, userName));
   					         	$('#tt').datagrid("unselectAll");
   							}
   			 			});
    			}
    		});
        }
      
      	//查看
		function rsvDetail(v_rsvID) {
			delCookie("v_rsvID");
			setCookie("v_rsvID", v_rsvID);
			setCookie("action_flag", "DETAIL");
			$parent("#parent_win").window({
                width: 714,
                height: 610,
                href: '/web-manager/rsv/rsvRuleDetail.html',
                title: '查看预约规则'
            });
		} 

		//修改
		function modifyRsv(v_rsvID,rowNum) {
			delCookie("v_rsvID");
			setCookie("v_rsvID", v_rsvID);
			setCookie("action_flag", "UPDATE");
			$parent("#parent_win").window({
                width: 714,
                height: 610,
                data: {v_rsvID: v_rsvID},
                href: '/web-manager/rsv/rsvRuleDetail.html',
                title: '修改预约规则',
                onClose:function () {
                		var userName = $("#userName").val();
		                var begindate = $("#begindate").datebox('getValue'); 
		                var enddate = $("#enddate").datebox('getValue');
		                var backupStatus = $("#backup_status").val();
		                
		                if (backupStatus == '全部') {
		            		backupStatus = null;
		            	}
		            	else if (backupStatus == '未归档') {
		            		backupStatus = 0;
		            	}
		            	else if (backupStatus == '已归档') {
		            		backupStatus = 1;
		            	}
						var p = $("#tt").datagrid('getPager');
			            var obj = $(p).pagination('options');
			         	$("#tt").datagrid('loadData', getRsvList(obj.pageNumber, obj.pageSize, begindate, enddate, backupStatus, userName));
			         	var index=obj.pageSize-((obj.pageNumber*obj.pageSize)-rowNum)-1;
			         	$('#tt').datagrid("selectRow", index);
                }
            });
		} 

		//归档
		function backupRsv(v_rsvID,rowNum) {
			$.messager.confirm('归档','真的要归档吗？',function(r){
    			if (r){
    				$.post("/web-manager/rsvManager/backupRsv.do", 
   						{v_rsvID : v_rsvID},
   						function(result){
   							if(result.code==0){
   								var userName = $("#userName").val();
   				                var begindate = $("#begindate").datebox('getValue'); 
   				                var enddate = $("#enddate").datebox('getValue');
   				                var backupStatus = $("#backup_status").val();
   				                
   				                if (backupStatus == '全部') {
   				            		backupStatus = null;
   				            	}
   				            	else if (backupStatus == '未归档') {
   				            		backupStatus = 0;
   				            	}
   				            	else if (backupStatus == '已归档') {
   				            		backupStatus = 1;
   				            	}
   								var p = $("#tt").datagrid('getPager');
   					            var obj = $(p).pagination('options');
   					         	$("#tt").datagrid('loadData', getRsvList(obj.pageNumber, obj.pageSize, begindate, enddate, backupStatus, userName));
	   					        var index=obj.pageSize-((obj.pageNumber*obj.pageSize)-rowNum)-1;
	   				         	$('#tt').datagrid("selectRow", index);
   								$.messager.show({title: '提示', msg: "归档成功"});
   							}else{
   								$.messager.show({title: '提示', msg: "归档失败," + result.errorDescription});
   							}
   			 		});
    			}
    		});
		} 

      	//导出
		function exportData(v_rsvID,v_backupStatus,v_rsvName,v_rsvDescrible) {
			$.messager.confirm('导出','真的要导出吗？',function(r){
    			if (r){
    				$.post("/web-manager/rsvManager/exportData.do", 
       						{v_rsvID : v_rsvID,
    						 v_backupStatus:v_backupStatus,
    						 v_rsvName:v_rsvName,
    						 v_rsvDescrible:v_rsvDescrible},
       						function(result){
			    				var code=result.code;
			    				code=parseInt(code);
			    				if (!isNaN(code)) {
										var errorInfo = "导出失败," + result.errorDescription;
				    					$.messager.show({title: '错误', msg: errorInfo});
			    				}else{
			    					$("#v_rsvID").val(v_rsvID);
				    				$("#v_backupStatus").val(v_backupStatus);
				    				$("#v_rsvName").val(v_rsvName);
				    				$("#v_rsvDescrible").val(v_rsvDescrible);
				    				$("#form_id").submit();
				    				$.messager.show({title: '成功', msg: "导出成功"});
			    				}
    			});	
    			}
    		});
      	}
		      
      	//获得列表数据
        function getRsvList(v_pageIndex, v_pageSize, v_startDate, v_stopDate, v_backupStatus, v_reMark) {
      		$.ajax({
    			type : "GET",
    			url : "/web-manager/rsvManager/rsvList.do",
    			data : {
    				"v_pageIndex": v_pageIndex,
    				"v_pageSize": v_pageSize,
    				"v_startDate": v_startDate,
    				"v_stopDate": v_stopDate,
    				"v_backupStatus": v_backupStatus,
    				"v_reMark": v_reMark
    			},
    			dataType : 'json',
    			async : false,
    			success : function(json) {
    				if(json.code == '0' || json.code == 0){
    					var totalCount = json.dataObject.totalCount;
    					var reservationList  = json.dataObject.reservationList;
    					$.each(reservationList,function(i){
    						if(reservationList[i]['backupStatus']==0){
    							reservationList[i]['backupStatus']='未归档'
    						}else{
    							reservationList[i]['backupStatus']='已归档'
    						}
    					});
    					reservationData = {"total":totalCount,"rows":reservationList};
    				}
    				else {
    					var errorInfo = "加载失败," + json.errorDescription;
    					$.messager.show({title: '错误', msg: errorInfo});
					}
    			}
    		});
    		
    		return reservationData;
    	}
        
        //监听窗口大小变化
        window.onresize = function () {
            setTimeout(domresize, 300);
        };
        //改变表格宽高
        function domresize() {
            $('#tt').datagrid('resize', {
                height: $("#body").height() - $('#search_area').height() - 5,
                width: $("#body").width()
            });
        }
        /**
         * 判断字符串是否为空
         * @param str
         * @returns {boolean}
         */
        function isempty(str) {
            if (str != null && str != "" && str != undefined && str.length > 0) {
                return true;
            }
            return false;
        }
         
         /**
           * 放置cookie 数据
           * @param {} name
           * @param {} value
           */
          function setCookie(name,value){ 
             var exp = new Date(); 
             exp.setTime(exp.getTime() + 60*60*1000); //设置时间为30*24小时有效
             document.cookie = name + "="+ escape (value) + ";path=/;expires=" + exp.toGMTString(); 
         } 

           /*获取到Cookie中的值*/
           function getCookie(name){
               var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
               if(arr=document.cookie.match(reg))
                   return unescape(arr[2]);
               else 
                   return ""; 
           }
           
         /**
          * 删除Cookies
          * @param {} name
          */
         function delCookie(name){
        	setCookie(name, "", -1);  
         } 

    </script>
</head>
<body class="easyui-layout">
<div id="body" region="center">
    <!-- 查询条件区域 -->
    <div id="search_area">
        <div id="conditon">
            <form id="ff">
                <table border="0">
                    <tr>
                        <td>&nbsp;&nbsp;开始日期：</td>
                        <td><input class="easyui-datebox" name="begindate" id="begindate" style="width:100px"></td>
                        <td>&nbsp;&nbsp;结束日期：</td>
                        <td><input class="easyui-datebox" name="enddate" id="enddate" style="width:100px"></td>
                        <td>&nbsp;&nbsp;归档状态：</td>
                        <td>
                            <select id="backup_status">
                                <option id="all">全部</option>
                                <option id="no">未归档</option>
                                <option id="yes">已归档</option>
                            </select>
                        </td>
                        <td>&nbsp;&nbsp;规则名称：</td>
                        <td><input name="userName" id="userName"/></td>
                        <td>
                            <a href="javascript:void(0)" class="easyui-linkbutton my-search-button"
                               iconCls="icon-search" id="search" plain="true">查询</a>
                            <a href="javascript:void(0)" class="easyui-linkbutton my-search-button" iconCls="icon-reset"
                               id="reset" plain="true">重置</a>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
    <!--导出文件用的-->
    <form action="/web-manager/rsvManager/exportData.do" id="form_id" method="post">
    	<input type="hidden" name="v_rsvID" id="v_rsvID"/>
    	<input type="hidden" name="v_backupStatus" id="v_backupStatus"/>
    	<input type="hidden" name="v_rsvName" id="v_rsvName"/>
    	<input type="hidden" name="v_rsvDescrible" id="v_rsvDescrible"/>
    </form>
    <!-- 数据表格区域 -->
    <table id="tt" style="table-layout:fixed;"></table>
    <!-- 表格顶部工具按钮 -->
    <div id="tt_btn">
        <a href="javascript:void(0)" id="save" class="easyui-linkbutton" iconCls="icon-add" plain="true">新增</a>
        <a href="javascript:void(0)" id="syncRsvs" class="easyui-linkbutton" iconCls="icon-reload" plain="true">同步</a>
    </div>
    
</div>
</body>
</html>
